#!  python
# -*- coding: UTF-8 -*-
'''
@Author ：Star
@Date ：2022/9/20  
'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep


op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches", ["enable-automation"])
op.add_experimental_option("useAutomationExtension", False)
driver =webdriver.Chrome(options=op)

driver.get("http://news.baidu.com")
sleep(2)
ele = driver.find_element(By.XPATH,"/html/body/div[3]/div[2]/div[1]/div/div[3]/div[1]/div/ul/li[1]/strong/a")
hotspot = ele.text  #获取点击之前的内容
print(hotspot)
sleep(2)
ele.click()
print(driver.title)
sleep(2)

# 找出新窗口：
new_window = driver.window_handles[1]   #  '-1'代表打开的最后一个窗口
# 切换到新窗口：
driver.switch_to.window(new_window)


sleep(2)
print(driver.title)

assert hotspot in driver.title

# if hotspot in driver.title:
#     print("正确")
# else:
#     print("错误")

driver.quit()


